package utils

import (
	"bytes"
	"fmt"

	lzstring "github.com/daku10/go-lz-string"
)

var secret = []byte{8, 2, 1, 2, 1, 6}

func checkVersion(b []byte) string {
	a := b[len(b)-6:]
	if bytes.Equal(a, secret) {
		return "v2"
	}
	return "v1"
}

func Decompress(s []byte) (string, error) {
	switch checkVersion(s) {
	case "v1":
		return lzstring.DecompressFromUint8Array(s)
	case "v2":
		return string(s[:len(s)-6]), nil
	}
	return "", fmt.Errorf("unrecognized version")
}
